package com.jia.train.member.controller;

import com.jia.train.global.page.PageResponse;
import com.jia.train.global.response.BaseResponse;
import com.jia.train.member.request.PassengerQueryRequest;
import com.jia.train.member.request.PassengerSaveRequest;
import com.jia.train.member.response.PassengerQueryResponse;
import com.jia.train.member.response.PassengerSaveResponse;
import com.jia.train.member.service.PassengerService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/passenger")
public class PassengerController {

    @Resource
    private PassengerService passengerService;

    @PostMapping("/insert")
    public BaseResponse<PassengerSaveResponse> insertPassenger(@Valid @RequestBody PassengerSaveRequest request) {
        PassengerSaveResponse response = passengerService.insert(request);
        return new BaseResponse<>(response);
    }

    @GetMapping("/query")
    public BaseResponse<PageResponse<PassengerQueryResponse>> query(@Valid PassengerQueryRequest request) {
        PageResponse<PassengerQueryResponse> responseList = passengerService.selectPage(request);
        return new BaseResponse<>(responseList);
    }

    @DeleteMapping("/delete/{id}")
    public BaseResponse<String> delete(@PathVariable Long id) {
        passengerService.deletePassenger(id);
        return new BaseResponse<>("success");
    }

    @GetMapping("/list")
    public BaseResponse<List<PassengerQueryResponse>> list() {
        List<PassengerQueryResponse> responseList = passengerService.selectList();
        return new BaseResponse<>(responseList);
    }


}
